package org.opu.gui.docviewer.table;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import javax.swing.text.BoxView;
import javax.swing.text.Element;
import javax.swing.text.View;


/**
 *  RowView is just cell container (cells are laid out horizontally).
 * RowView paints vertical borders to split cells and TableView
 * paints horizontal borders to split rows.
 *
 * @author yura
 */
public class RowView extends BoxView {

    /**
     *  Constructs a RowView.
     *
     * @param elem
     */
    public RowView(Element elem) {
        super(elem, View.X_AXIS);
    }

    @Override
    public float getPreferredSpan(int axis) {
        return super.getPreferredSpan(axis);
    }

    @Override
    protected void layout(int width, int height) {
        super.layout(width, height);
    }

    @Override
    public float getMinimumSpan(int axis) {
        return getPreferredSpan(axis);
    }

    @Override
    public float getMaximumSpan(int axis) {
        return getPreferredSpan(axis);
    }

    @Override
    public float getAlignment(int axis) {
        return 0;
    }

    @Override
    protected void paintChild(Graphics g, Rectangle alloc, int index) {
        super.paintChild(g, alloc, index);
        g.setColor(Color.black);
        int h = (int) getPreferredSpan(View.Y_AXIS) - 1;
        g.drawLine(alloc.x, alloc.y, alloc.x, alloc.y + h);
        g.drawLine(alloc.x + alloc.width, alloc.y, alloc.x + alloc.width, alloc.y + h);
    }
}
